<template>
  <div id="app" ref="fullHomePage">
    <router-view v-wechat-title='$route.meta.title' />
    <tab-bar v-if="show"></tab-bar>
  </div>
</template>

<script>
import TabBar from "@/components/tab/tabBar";
import { Base64 } from 'js-base64'
export default {
  components: {
    TabBar,
  },
  created(){
    
      window.jwt_token = () => {
        return this.$cookies.get("authtoken")
      }
      const time_now = () => {
        return window.parseInt(new Date().getTime()/1000)
      }
      if( window.location.pathname.indexOf("bind")!=-1 || window.location.pathname.indexOf("oauth")!=-1 || window.location.pathname.indexOf("wechat")!= -1 || window.location.pathname.indexOf("auth")!=-1){

      }else{
        var iswechat = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
        if(jwt_token() != 'undefined' && jwt_token() !=undefined ){ // 存在登陆数据
          let exp = JSON.parse(Base64.decode(jwt_token().split('.')[1])).exp
          if( exp < time_now() ){ // 权限是否过⑦
            if(iswechat){
              window.location.href = "/oauth/wechat?initURL="+encodeURIComponent(window.location.href)
              return
            }else{
              window.location.href = "/auth/login?initURL="+encodeURIComponent(window.location.href)
              return
            }
          }
        }else{
          if(iswechat){
            window.location.href = "/oauth/wechat?initURL="+encodeURIComponent(window.location.href)
            return
          }else{
            window.location.href = "/auth/login?initURL="+encodeURIComponent(window.location.href)
            return
          }
        }
      }
  },
  computed: {
    show: function () {
      console.log(window.location.pathname);
      return (window.location.pathname == '/' || window.location.pathname == '/order' || window.location.pathname == '/messages' || window.location.pathname  == '/user/collection' || window.location.pathname == '/user/self')
    },
  },
  name: 'App',
  data () {
    return {
      clientHeight: "",
    };
  },
  mounted() {
    this.clientHeight = `${document.documentElement.clientHeight}`;
    window.onresize = function temp() {
      this.clientHeight = `${document.documentElement.clientHeight}`;
    };
  },
  watch: {
    clientHeight: function() {
      this.changeFixed(this.clientHeight);
    }
  },
  methods: {
    changeFixed(clientHeight) {
      this.$refs.fullHomePage.style.minHeight = clientHeight + "px";
    }
  }
}

</script>

<style lang="scss">
#app {
  overflow: hidden;
  overflow-y: auto;
  background-color: #ffffff;
  .van-tabbar-item {
    img {
      display: block;
      margin: 0 auto;
      margin-bottom: 5px;
      width: 18px;
      height: 18px;
    }
  }
  .tagbar-name {
    font-size: 9px;
  }
}
</style>
<style>
/* {
  /* font-family: Microsoft YaHei !important ; */
/*}*/
* *::before {
  font-family: vant-icon !important;
}
</style>

